﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>

<%@ Import Namespace="System.Drawing" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Chart</title>
    <script language="C#" runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            //TextBoxUserId.Visible = false;
            TextBoxUserId.Value = Request.QueryString.Get("userId");
            if (String.IsNullOrWhiteSpace(TextBoxUserId.Value))
            {
                TextBoxUserId.Value = Guid.Empty.ToString();
            }
            SetColor();
        }

        private void SetColor()
        {
            Color[] myPalette = new Color[8]{
            Color.FromKnownColor(KnownColor.Salmon), 
            Color.FromKnownColor(KnownColor.Yellow),
            Color.FromKnownColor(KnownColor.Gray), 
            Color.FromKnownColor(KnownColor.Violet),
            Color.FromKnownColor(KnownColor.Pink),
            Color.FromKnownColor(KnownColor.Orange),
            Color.FromKnownColor(KnownColor.SkyBlue),
            Color.FromKnownColor(KnownColor.ForestGreen)
            };
            this.PieChart.Palette = ChartColorPalette.None;
            this.PieChart.PaletteCustomColors = myPalette;
        }
        
    </script>
</head>
<body style="font-family: Verdana, Arial, Helvetica, sans-serif;">
    <form id="form1" runat="server">
    <h2>
        Order Category Allocation</h2>
    <div>
        <asp:Chart ID="PieChart" runat="server" DataSourceID="SqlDataSourceCategory" BorderlineDashStyle="Solid">
            <Series>
                <asp:Series ChartType="Pie" Name="PieSeries" XValueMember="CategoryName" YValueMembers="TotalAmount"
                    ChartArea="ChartAreaPie" YValueType="Double">
                </asp:Series>
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="ChartAreaPie">
                </asp:ChartArea>
            </ChartAreas>
            <BorderSkin BackColor="BurlyWood" BackGradientStyle="LeftRight" BackSecondaryColor="Blue"
                SkinStyle="Emboss" />
        </asp:Chart>
        <asp:SqlDataSource ID="SqlDataSourceCategory" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseContext %>"
            SelectCommand="SELECT [TotalAmount], [CategoryName] FROM [vm_OrderByCategory] WHERE ([UserId] = @customerId)">
            <SelectParameters>
                <asp:ControlParameter Name="customerId" Type="String" DefaultValue="00000000-0000-0000-0000-000000000000"
                    ControlID="TextBoxUserId" />
            </SelectParameters>
        </asp:SqlDataSource>
    </div>
    <h2>
        History Orders Statistics</h2>
    <div>
        <asp:Chart ID="BarChart" runat="server" DataSourceID="SqlDataSourceDate" Width="900px">
            <Series>
                <asp:Series Name="SeriesBar" XValueMember="ODATE" YValueMembers="TotalAmount" IsValueShownAsLabel="True"
                    MarkerSize="3">
                </asp:Series>
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="ChartAreaBar">
                </asp:ChartArea>
            </ChartAreas>
            <BorderSkin BackColor="BurlyWood" BackGradientStyle="LeftRight" BackSecondaryColor="Blue"
                SkinStyle="Emboss" />
        </asp:Chart>
        <asp:SqlDataSource ID="SqlDataSourceDate" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseContext %>"
            SelectCommand="SELECT [ODATE], [TotalAmount] 
            FROM dbo.[vm_OrderByDate]
            WHERE UserId = @customerId
            ORDER BY [YYYYMM] ">
            <SelectParameters>
                <asp:ControlParameter Name="customerId" Type="String" DefaultValue="00000000-0000-0000-0000-000000000000"
                    ControlID="TextBoxUserId" />
            </SelectParameters>
        </asp:SqlDataSource>
    </div>
    <asp:HiddenField ID="TextBoxUserId" runat="server"></asp:HiddenField>
    </form>
</body>
</html>
